<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
  <div class="layui-card">
    <div class="layadmin-search">
      <form class="layui-form" method="post" lay-filter="form_channel_target">
        <div class="layui-inline">
          <div class="layui-form-label">日期范围</div>
          <div class="layui-inline" id="date_range">
            <div class="layui-input-inline">
              <input type="text" name="start_date" autocomplete="off" id="start_date" class="layui-input"
                     style="width: 100px" value="{{layui.router().search.start_date || ''}}" placeholder="开始日期"
                     readonly>
            </div>
            <div class="layui-input-inline">~</div>
            <div class="layui-input-inline">
              <input type="text" name="end_date" autocomplete="off" id="end_date" class="layui-input"
                     style="width: 100px" value="{{layui.router().search.end_date || ''}}" placeholder="结束日期"
                     readonly>
            </div>
          </div>
        </div>
        <div class="layui-inline layui-btn-group">
          <button type="submit" lay-submit class="layui-btn" lay-filter="submit_channel_target">
            <i class="layui-icon layui-icon-search"></i>查询
          </button>
        </div>
      </form>
    </div>
    <div class="layui-card-body">
      <div id="table_channel_target" lay-filter="table_channel_target"></div>
    </div>
  </div>
</script>
<script type="text/html" id="tpl_user_metrics">
  {{d.real_user_count}} / {{d.user_count}}
</script>
<script>
  layui.data.sendParams = function (obj) {
    layui.use(['table', 'laydate'], function () {
      let $ = layui.$
        , view = layui.view
        , admin = layui.admin
        , form = layui.form
        , table = layui.table
        , laydate = layui.laydate

      laydate.render({
        elem: '#date_range'
        , range: ['#start_date', '#end_date']
        , max: (new Date()).toDateString()
      });

      // 列表查询
      table.render({
        elem: '#table_channel_target'
        , url: 'agent-admin/channels/target/' + obj.id
        , page: false
        , cols: [[
          {title: '实名/注册', templet: '#tpl_user_metrics', minWidth: 120, align: "center"}
          , {title: '成交订单量', field: 'pay_order', width: 120, align: "center"}
          , {title: '成交总金额', field: 'pay_order_money', width: 120, align: "center"}
          , {title: '普单金额', field: 'order_amount', width: 120, align: "center"}
          , {title: '转售金额', field: 'resale_order_amount', width: 120, align: "center"}
          , {title: '盲盒金额', field: 'blind_order_amount', width: 120, align: "center"}
        ]]
      });

      //搜索
      form.on('submit(submit_channel_target)', function (d) {
        table.reload('table_channel_target', {
          where: {start_date: d.field.start_date, end_date: d.field.end_date},
          page: {curr: 1}
        });
        return false;
      })
    })
  }
</script>
